import {Icon,Modal ,Input,message,Spin} from 'antd';
import React from 'react';
import CryptoJS from "crypto-js";


class JsPage extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            key:'',
            window: false ,// 弹框
            disVisible: true,  //不显示
            visible: false,
            visible2: false,
            currentLine: 1,
            data:(window.erred <=3)?'':'你已经受限访问。',
        }

        if(props.location.search){
            const key = props.location.search.substring(1);
            if(key && key =='show'){
                this.state.window = true ;
            }
        }


    }

     pass = '';
     errord = 0;

    //AES  http://tool.chinaz.com/Tools/textencrypt.aspx  2889

    checkFor= (line,passs_, e) =>{
        this.pass =passs_ ;
        this.setState({
             currentLine: line,
             visible: true,
        });
    }

    onChangeUserName = (e) => {
        this.setState({ key: e.target.value });
    }

    handleOk = (e) => {
        if(this.state.key){
            let pass_ =  this.pass.trim().split('\n');
            let word ='';
            pass_.forEach(function(value){
                word+=value;
            });
            try{
                let bytes  = CryptoJS.AES.decrypt(word,this.state.key);
                let right_pass = bytes.toString(CryptoJS.enc.Utf8);
                if(right_pass){
                    this.setState({
                        visible: false,
                        pass1: true,
                        data:right_pass
                    });
                }else {
                    this.showNothing();
                }
            }catch (e) {
                this.showNothing();
            }

        }else{
            this.showNothing();
        }
    }
    handleCancel = (e) => {
        this.setState({
            visible: false,
            visible1: false,
            visible2: true,
        });
    }


    handleOk0 = (e) => {
        if(this.state.key){
            let word =  "U2FsdGVkX1/QLZQYig/1DpXDqTtk6i7JjnmkJcC+Is0=";
            try{
                let bytes  = CryptoJS.AES.decrypt(word,this.state.key);
                let right_pass = bytes.toString(CryptoJS.enc.Utf8);
                if(right_pass){
                    this.setState({
                        window: false,
                        disVisible: false,
                    });
                }else {
                    this.showNothing();
                }
            }catch (e) {
                this.showNothing();
            }

        }else{
            this.showNothing();
        }
    }

    showNothing = () => {
        this.setState({
            visible: false,
            data:"error pass " + window.erred
        });
        if(this.errord){
            this.errord = this.errord +1 ;
            if(this.errord >3){
                message.error('你已经受限访问');
                window.location.replace("http://news.baidu.com/")
            }
        }else {
            this.errord = 1 ;
        }
    }

    render() {
        const suffix = key ? <Icon type="close-circle" onClick={this.emitEmpty} /> : null;
        const {key} = this.state;
        return (
            <div>
                <Modal
                    visible={this.state.window}
                    onOk={this.handleOk0}
                    onCancel={this.handleCancel}>
                    <img src={require('../../imgs/forbid.png' )}  style={{height:"100%",width:"100%",marginBottom:"10px"}}/>
                    <Input
                        placeholder="请输入通行码!"
                        prefix={<Icon type="question-circle-o" style={{ color: 'rgba(0,0,0,.25)' }} />}
                        suffix={suffix}
                        value={key}
                        type="password"
                        onChange={this.onChangeUserName}
                        ref={node => this.keyInput = node}
                    />
                </Modal>
                <Modal
                    visible={this.state.visible2}
                    closable = {false}
                    footer={null}
                    >
                    <img src={require('../../imgs/warn.png' )}  style={{height:"100%",width:"100%",marginBottom:"10px"}}/>
                </Modal>

                <Modal
                    title="未经允许不可查看原文!"
                    visible={this.state.visible}
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}>
                    <img src={require('../../imgs/wx.png' )}  style={{height:"100%",width:"100%",marginBottom:"10px"}}/>
                    <Input
                        placeholder="请输入验证码!"
                        prefix={<Icon type="question-circle-o" style={{ color: 'rgba(0,0,0,.25)' }} />}
                        suffix={suffix}
                        value={key}
                        type="password"
                        onChange={this.onChangeUserName}
                        ref={node => this.keyInput = node}
                    />
                </Modal>



                {this.state.disVisible?
                    <div>
                        <Spin size="large">系统检测到你不是亲爱的xian,请给xian发红包才可以浏览</Spin>
                    </div>

                    :

                   <div> =======
               <table>
                   <thead><td>编号</td><td>名称</td><td>链接</td><td>00</td><td>01</td><td>邮箱/手机</td><td>有效</td><td>显示</td><td>备注</td></thead>
                   <tbody>

                       <tr>
                           <td>01</td>
                           <td>码云</td>
                           <td><a href={"https://gitee.com"}> https://gitee.com</a></td>
                           <td>569***3@qq.com</td>
                           <td>{this.state.currentLine ==1 ? this.state.data : ''}</td>
                           <td>569***3@qq.com</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,1,"U2FsdGVkX18PdGKFQ+3CyC5Pp8q+gY+I7A0r5cGRatc=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>

                       <tr>
                           <td>02</td>
                           <td>码云</td>
                           <td><a href={"https://gitee.com"}> https://gitee.com</a></td>
                           <td>nick****</td>
                           <td>{this.state.currentLine ==2 ? this.state.data : ''}</td>
                           <td>nick07**@163.com</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,2,"U2FsdGVkX19ynER88qaNh2g5iOY/bqh2xp/xp/SHy6U=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>

                       <tr>
                           <td>03</td>
                           <td>广州发友</td>
                           <td><a href={"https://www.baidu.com"}>用友</a></td>
                           <td>180******</td>
                           <td>{this.state.currentLine ==3 ? this.state.data : ''}</td>
                           <td>180******</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,3,"U2FsdGVkX1+eUZK3yXa8YqHxjGUT2eibNDwZcvai7O0=")}> <Icon type="eye" /></a></td>
                           <td>18～17</td>
                       </tr>


                       <tr>
                           <td>04</td>
                           <td>CSDN</td>
                           <td><a href={"https://www.csdn.net"}>CSDN</a></td>
                           <td>180******</td>
                           <td>{this.state.currentLine ==4 ? this.state.data : ''}</td>
                           <td>180******</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,4,"U2FsdGVkX1/jhJlz6Z77AKIgpSdDuIygX2rn5oUZIJU=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>

                       <tr>
                           <td>05</td>
                           <td>汪钉</td>
                           <td><a href={"https://www.baidu.com"}>汪钉</a></td>
                           <td>138*****9</td>
                           <td>{this.state.currentLine ==5 ? this.state.data : ''}</td>
                           <td>138*****9</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,5,"U2FsdGVkX1/1JF/++ALdyUQ31wlvf82GTWaGJqZxFv8=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>

                       <tr>
                           <td>06</td>
                           <td>CL</td>
                           <td><a href={"https://www.baidu.com"}>CL</a></td>
                           <td>1</td>
                           <td><a href={this.state.data}>{this.state.currentLine ==6 ? this.state.data : ''}</a></td>
                           <td>1</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,6,"U2FsdGVkX19K7iq7KGycPiDw5+MfhLzvU3m4zeNdsD6yogz/OqGenO83ilA6GOuw\n" +
                               "k5c3Vst5TYW/UBd7zRjr4A==")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>

                       <tr>
                           <td>07</td>
                           <td>iteye</td>
                           <td><a href={"https://www.iteye.com/login"}>iteye</a></td>
                           <td>onway417</td>
                           <td>{this.state.currentLine ==7 ? this.state.data : ''}</td>
                           <td>273***.com</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,7,"U2FsdGVkX18dqkR7x2qTV1Ql3oJIYk/WeiQQFYOIxPU=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>
                       <tr>
                           <td>08</td>
                           <td>摇号</td>
                           <td><a href={"http://xkctk.hangzhou.gov.cn/?"}>摇号</a></td>
                           <td>180***</td>
                           <td>{this.state.currentLine ==8 ? this.state.data : ''}</td>
                           <td>180***</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,8,"U2FsdGVkX19QXJzpLzZIzrdM95A/0vFG7LLA2obc8E8=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>
                       <tr>
                           <td>09</td>
                           <td>企业招商</td>
                           <td><a href={"https://www.baidu.com"}>企业招商</a></td>
                           <td>180***</td>
                           <td>{this.state.currentLine ==9 ? this.state.data : ''}</td>
                           <td>180***</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,9,"U2FsdGVkX1+jz9prZlqTE/An3VjWz+R7WI3WIIfbQPU=")}> <Icon type="eye" /></a></td>
                           <td>兑积分*9**30,07~06</td>
                       </tr>

                       <tr>
                           <td>10</td>
                           <td>九度</td>
                           <td><a href={"https://www.baidu.com"}>九度</a></td>
                           <td>exppd</td>
                           <td>{this.state.currentLine ==10 ? this.state.data : ''}</td>
                           <td>180***</td>
                           <td>无效</td>
                           <td><a href="javascript:void(0)" onClick={this.checkFor.bind(this,10,"U2FsdGVkX1845zH9tQRhNbbWWIn4S25Lbo8RlFC5GXo=")}> <Icon type="eye" /></a></td>
                           <td></td>
                       </tr>

                   </tbody>

               </table>
                   </div>
                }
            </div>
        );
    }
}

export default JsPage;